package com.neborosoft.FlyingDog.android.playing.modes;

import android.app.Activity;
import android.view.View;
import com.neborosoft.FlyingDog.R;
import com.neborosoft.FlyingDog.android.MyActivity;
import com.neborosoft.FlyingDog.android.gui.adapters.listview.AlbumListAdapter;
import com.neborosoft.FlyingDog.android.gui.adapters.listview.ArtistListAdapter;
import com.neborosoft.FlyingDog.android.gui.adapters.listview.SongsPlayListAdapter;
import com.neborosoft.FlyingDog.logic.database.AudioDataManager;
import com.neborosoft.FlyingDog.logic.database.content.identified.Artist;
import com.neborosoft.FlyingDog.logic.database.providers.ArtistTree;
import com.neborosoft.FlyingDog.logic.search.suggestions.ArtistSuggestionsProvider;
import com.neborosoft.FlyingDog.logic.search.suggestions.SuggestionsProvider;
import com.neborosoft.android.gui.Gui;
import com.neborosoft.android.gui.adapters.listview.ViewArrayAdapter;
import com.neborosoft.android.gui.views.LayoutRadioButtonGroup;
import com.neborosoft.android.gui.wrappers.ListViewSwitcher;
import com.neborosoft.lib.API_8.Collections;
import com.neborosoft.lib.FlyingDogRuntimeException;
import com.neborosoft.lib.collections.list.NavigationList;
import com.neborosoft.lib.collections.tree.AsyncNTreeWrapper;
import com.neborosoft.lib.collections.tree.MultiStepsNavigationTree;

/**
 * Created with IntelliJ IDEA.
 * User: CM
 * Date: 01.12.12
 * Time: 21:57
 * To change this template use File | Settings | File Templates.
 */
public class ArtistsMode extends PlayingModeWithNavigationTabs {
    private static final int ARTISTS_LEVEL = 0;
    private static final int ALBUMS_LEVEL = 1;
    private static final int SONGS_LEVEL = 2;
    private static final int STEPS_COUNT_FROM_ARTIST_TO_SONGS = 1;

    @Override
    protected Class<? extends ViewArrayAdapter> getListViewAdapterClass(int level) {
        switch(level){
            case ARTISTS_LEVEL: return ArtistListAdapter.class;
            case ALBUMS_LEVEL: return AlbumListAdapter.class;
            case SONGS_LEVEL: return SongsPlayListAdapter.class;
            default: throw new FlyingDogRuntimeException("invalid level request");
        }
    }

    @Override
    protected int getListViewResourceIdForLevel(int level) {
        if(level <= ALBUMS_LEVEL){/*for album and artist level*/
            return Constants.gridViewSwitcherResource;
        }
        else {
            return Constants.listViewSwitcherResource;
        }
    }

    @Override
    protected int getTabsResourceId() {
        return R.id.artistTabs;
    }

    @Override
    protected int getTabsLevel() {
        return 0;
    }

    @Override
    protected int getStepsCountByTabId(int tabId) {
        switch (tabId) {
            case R.id.songsOfArtistTab: return STEPS_COUNT_FROM_ARTIST_TO_SONGS;
            case R.id.albumsOfArtistTab: return MultiStepsNavigationTree.DEFAULT_STEPS_COUNT;
            default: throw new FlyingDogRuntimeException("invalid tabId");
        }
    }

    public ArtistsMode(Activity activity, ListViewSwitcher listView, ArtistTree tree) {
        super(activity, listView, tree);
    }

    @Override
    public Object performSearch(String query) {
        NavigationList<Artist> artists = AudioDataManager.getInstance().getArtists(query);
        setNavigationListNotifiers(artists);

        return artists;
    }

    @Override
    protected SuggestionsProvider createSuggestionsProvider() {
        return new ArtistSuggestionsProvider();
    }
}
